<?php
namespace app\api\controller;

use app\api\controller\Base;
use think\Db;

class My extends Base
{
    public function _empty()
    {
        header("Location:/404.html");
        exit;
    }
    public function ajax()
    {
        $data=input('post.');
        if(!Base::lizhili($data,true)){
            header("Location:/404.html");
            exit;
        }
		
		//查看是否有权限
		if ($data['type']=='get_my_info') {
			if($user=Db::name('member')->where('token',$data['token'])->find()){
				 return ['code'=>1,'message'=>'成功','data'=>$user];
			}else{
				return ['code'=>0,'message'=>'失败'];
			}
		}
       
        return ['code'=>0,'message'=>'非法获取'];
    }
    public function update()
	{
	    $data=input('post.');
	    if (!isset($data["lizhili"]) or !isset($data["type"]) or $data["lizhili"]!= "0d89b868429be6158ba1ebc0f7c073de") {
	        header("Location:/404.html");
	        exit;
	    }
		
		//修改头像
		if ($data['type']=='update_my_img') {
			$file = request()->file('');
			if (isset($file['file'])) {
				$info = $file['file']->move('uploads_tou');
				$li=strtr($info->getSaveName(), " \ ", " / ");
				$key='/uploads_tou/'.$li;
				Db::name('user')->where('token', $data['token'])->update(['avatarUrl'=>$key]);
				return	['code'=>1,'data'=>$key];
			} else {
			    return ['code'=>0,'message'=>'上传错误'];
			}
		}
		
		
	    return ['code'=>0,'message'=>'非法获取'];
	}
}
